package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.system.domain.CompanyInfo;
import com.ruoyi.system.dto.film.FilmPermitInfoAddDto;
import com.ruoyi.system.dto.film.FilmPermitInfoSearchVo;
import com.ruoyi.utils.PageRequest;
import com.ruoyi.utils.PageResult;
import com.ruoyi.utils.PaginationHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FilmPermitInfo;
import com.ruoyi.system.service.IFilmPermitInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 公映许可证信息Controller
 *
 * @author 周志雄
 * @date 2024-03-09
 */
@Api(tags = "公映许可证信息API")
@RestController
@RequestMapping("/system/permitInfo")
public class FilmPermitInfoController extends BaseController
{
    @Autowired
    private IFilmPermitInfoService filmPermitInfoService;

    /**
     * 查询公映许可证信息列表
     */
    @ApiOperation("查询公映许可证信息列表")
    @PreAuthorize("@ss.hasPermi('system:permitInfo:list')")
    @PostMapping("/list")
    public AjaxResult<PageResult<FilmPermitInfo>> list(@RequestBody FilmPermitInfoSearchVo filmPermitInfoSearchVo)
    {
        List<FilmPermitInfo> list = filmPermitInfoService.selectFilmPermitInfoList(filmPermitInfoSearchVo);
//        PageRequest pageRequest = new PageRequest(filmPermitInfoSearchVo.getPageNum(), filmPermitInfoSearchVo.getPageSize());
//        PageResult<FilmPermitInfo> pageResult = PaginationHelper.paginateList(list, pageRequest);
        List<FilmPermitInfo> list1 = filmPermitInfoService.list();
        int totalPages = 0;
        if (!list1.isEmpty()){
            totalPages=list1.size()/filmPermitInfoSearchVo.getPageSize();
        }
        PageResult<FilmPermitInfo> pageResult = new PageResult<>(list1.size(),totalPages,list,filmPermitInfoSearchVo.getPageNum(),filmPermitInfoSearchVo.getPageSize());
        return AjaxResult.success(pageResult);
    }

    /**
     * 导出公映许可证信息列表
     */
    @ApiOperation("导出公映许可证信息列表")
    @PreAuthorize("@ss.hasPermi('system:permitInfo:export')")
    @Log(title = "公映许可证信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody FilmPermitInfoSearchVo filmPermitInfoSearchVo)
    {
        List<FilmPermitInfo> list = filmPermitInfoService.selectFilmPermitInfoList(filmPermitInfoSearchVo);
        ExcelUtil<FilmPermitInfo> util = new ExcelUtil<FilmPermitInfo>(FilmPermitInfo.class);
        util.exportExcel(response, list, "公映许可证信息数据");
    }

    /**
     * 获取公映许可证信息详细信息
     */
    @ApiOperation("根据ID获取公映许可证信息详细信息")
    @PreAuthorize("@ss.hasPermi('system:permitInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<FilmPermitInfo> getInfo(@ApiParam(value = "公映许可证ID") @PathVariable("id") Long id)
    {
        return AjaxResult.success(filmPermitInfoService.selectFilmPermitInfoById(id));
    }

    /**
     * 新增公映许可证信息
     */
    @ApiOperation("新增公映许可证信息")
    @PreAuthorize("@ss.hasPermi('system:permitInfo:add')")
    @Log(title = "公映许可证信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult<String> add(@RequestBody FilmPermitInfoAddDto filmPermitInfoAddDto)
    {
        FilmPermitInfo filmPermitInfo = new FilmPermitInfo();
        BeanUtils.copyProperties(filmPermitInfoAddDto,filmPermitInfo);
        filmPermitInfoService.insertFilmPermitInfo(filmPermitInfo);
        return AjaxResult.success("新增公映许可证信息成功");
    }

    /**
     * 修改公映许可证信息
     */
    @ApiOperation("修改公映许可证信息")
    @PreAuthorize("@ss.hasPermi('system:permitInfo:edit')")
    @Log(title = "公映许可证信息", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult<String> edit(@RequestBody FilmPermitInfo filmPermitInfo)
    {
        filmPermitInfoService.updateFilmPermitInfo(filmPermitInfo);
        return AjaxResult.success("修改公映许可证信息成功");
    }

    /**
     * 删除公映许可证信息
     */
    @ApiOperation("删除公映许可证信息")
    @PreAuthorize("@ss.hasPermi('system:permitInfo:remove')")
    @Log(title = "公映许可证信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult<String> remove(@ApiParam(value = "公映许可证ID列表") @PathVariable Long[] ids)
    {
        filmPermitInfoService.deleteFilmPermitInfoByIds(ids);
        return AjaxResult.success("删除公映许可证信息成功");
    }
}
